// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/deliverorder/api/WoDeliverApi'

import OneClass from '@api/deliverorder/model/QueryWoDeliverDetailReq'
import EditClass from '@api/deliverorder/model/UpdateWoDeliverReq'
import DelClass from '@api/deliverorder/model/DeleteWoDeliverReq'
import BaseClass from '@api/deliverorder/model/WoDeliverDto'
import FileClass from '@api/deliverorder/model/WoDeliverFileDto'

import API from '@admin/components/detail/DetailRepair/store/API'

const CLIENT = CORE.grpcCLIENT(Client)
const FILE = [FileClass, 'woDeliverFileDto', 1]

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  validOne: API.validOne,
  async getOne({ id }, TIP = '查询详情') {
    const DTO = CORE.grpcDTO(OneClass, { id })
    const resp = await CORE.grpc(TIP, CLIENT, 'queryWoDeliverDetail', DTO)
    return resp.woDeliverDto || {}
  },
  transOne: API.transOne,

  // —————————————————————————————— 改 —————————————————————————————— //

  transEdit: API.transEdit,
  async edit(one, TIP = '修改') {
    const BASE = [BaseClass, 'woDeliverDto', '', (dto, obj) => CORE.grpcDTO(dto, obj, FILE)]
    const DTO = CORE.grpcDTO(EditClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'updateWoDeliver', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async del({ id }, TIP = '删除') {
    const DTO = CORE.grpcDTO(DelClass, { ids: id })
    await CORE.grpc(TIP, CLIENT, 'deleteWoDeliver', DTO)
    return CORE.grpcOK(TIP)
  },
}
